import copy
from functools import reduce

#闭包
def outer_function():
    external_var = "I am an external variable"
    def inner_function():
        return external_var + "   abcd"
    return inner_function()

#a = outer_function()
#print(a)

#装饰器
def my_decorator(func):
    def abc(*args, **kwargs):
        print("函数执行前")
        func(*args, **kwargs) # 使用 *args 和 **kwargs 调用原始函数 
        print("函数执行后")
    return abc

# 使用装饰器 
@my_decorator
def greet(name,b):
    print(f"Hello, {name}{b}!")

# 调用函数
#greet("Alice","hhhhh")


#浅拷贝和深拷贝
a = [1,2,3,4,['a','b']]
b = a
c = copy.copy(a)
d = copy.deepcopy(a)

a[0] = 999

print(f"a的结果是：{a}，地址是：{id(a)}")

#这里是赋值地址引用
print(f"b的结果是：{b}，地址是：{id(b)}")

print(f"c的结果是：{c}，地址是：{id(c)}")

print(f"d的结果是：{d}，地址是：{id(d)}")

print("-"*100)

a[4][1] = 'AA'

print(f"a的结果是：{a}，地址是：{id(a)}")

#浅拷贝，这里是赋值地址引用
print(f"b的结果是：{b}，地址是：{id(b)}")

print(f"c的结果是：{c}，地址是：{id(c)}")

print(f"d的结果是：{d}，地址是：{id(d)}")

arr = [8989,777709,31,44,88,107,456464,84121,85203,64,10.5,656,89112,177,355,211,12.5,631]
#a = [i * 3 for i in arr]
a  = (i * 3 for i in arr)
print(f"a的地址空间：{a}，值：{list(a)}")

result_arr = lambda x : (i*3 for i in x)

print(f"result_arr()的地址空间：{result_arr}，值：{list(result_arr(arr))}")

print("-"*100)

add_lambda = lambda y,x : x + y
#print(add_lambda(2,3))
""" _octo:GH1.1.1615866955.1712754215 """
temp = '_octo=GH1.1.1615866955.1712754215; _device_id=6da1ad3e7962597d40effa50fd91e0f9; preferred_color_mode=light; tz=Asia%2FShanghai; tz=Asia%2FShanghai; color_mode=%7B%22color_mode%22%3A%22auto%22%2C%22light_theme%22%3A%7B%22name%22%3A%22light%22%2C%22color_mode%22%3A%22light%22%7D%2C%22dark_theme%22%3A%7B%22name%22%3A%22dark%22%2C%22color_mode%22%3A%22dark%22%7D%7D; has_recent_activity=1; saved_user_sessions=78992987%3AYV7D2oPu-D2aujUSLKhmuLg9lF3HijV0U4X6RgIJyIqP9cP3; user_session=YV7D2oPu-D2aujUSLKhmuLg9lF3HijV0U4X6RgIJyIqP9cP3; __Host-user_session_same_site=YV7D2oPu-D2aujUSLKhmuLg9lF3HijV0U4X6RgIJyIqP9cP3; logged_in=yes; dotcom_user=ll577444; _gh_sess=Fv9kuASd8AawQGiuez9elPQcXA3zDGCcS0e2bLYQ1LsCviAvAOfRvQxeZM%2FzZsp1SPeL%2Fl3SvjQ20D7ONQQ6gINnO3FiF1LBc9pONoh9pN2t1X1iawhEPIkTMIyKAHrU26ksOhWpyXhcHtQ2F60ZzC%2FsK7U4PIlpUxguvLlRS2DIdMoTjmwHSQFvSDfp3Ronh7oNNL%2FeSWnh2Jxkl2aG6AZq8gXPHICZBeTlWBLiMt4tcst9guKKF3l4mtmUN2E3UcqId1s%2BaJ3yjL9iCuhUodds3lZmq%2B1VElzRbavocFUT2IOxGBOCSLNkG3veQENKRhBkPaT5ugydTO5wFBuG%2FGn8ULA7d2UlJpzB6bMmBK8jEfWtwBks2yxozORRWBzITdS2DZ35SAYdYbcSQaE37zVn7e7iOnwFEwUAQ%2Fmc%2B9wxrY4qbR8uLgUVQPgKa%2BCCVgacFzYI2Vrj40WmNeZiMuj9e%2FJZrsetNRKj30%2Bi%2BargJGAagyXA1s2MfSG29WNqS9aS3XfeTLKRDSXKx5Ue76Y9%2BWeOn9zUChZGSk9WZZCJMrMb2sHWoBHH6AvLbNb2Wq%2Bgbhv0B4lv0r%2B8I5WD5IkF5wJPXskVMlyd8ux2z3yf%2FkVuvrxES7HshBp8bQN%2Fozc%2F42HLFDywd3L5MmtLtXBQVVzI%2FTnt5p0eMsQYwKQytUdCFM1wOxgZN1iPXjAFNNKCi7DdnYWOZx9UKVgvQucKC49sn9Pv1aawR96TXQb7NI07Ee4zjNjV7DYYXFM%2FzmQmk00WiH4YYhSK3%2BcSrz8tpNBjqFIn3eQlEWh4Mbt2mYJZ%2Ff0zMorR1xcPscx7%2FOffq%2FFgfubbcriQoWdkh0weHld3%2BXiAbJVhUnXJ10EmsCauLsSDSA%3D%3D--qyTWhC8nmlvoxTQC--B9B3LLliq9meKT3s%2FYXU%2BA%3D%3D'

cookies = {i.split("=")[0]:i.split("=")[1] for i in temp.split("; ")}
print(cookies)

items = ['apple', 'banana', 'cherry']
item_dict = {index: item for index, item in enumerate(items)}
print(f"item_dict：{item_dict}")

print("-"*100)

#map函数
numbers_arr = [11,22,33,44,55,66,77,88]

squared_numbers = map(lambda x:x ** 2,numbers_arr)
result_arr = lambda x : (i ** 2 for i in x)

print(list(squared_numbers))
print(list(result_arr(numbers_arr)))

print("-"*100)

#累加
arr_number = [1,2,3,4,5,6]
result = reduce(lambda x,y:x+y,arr_number)
print(result)

print("-"*100)

#filter过滤
result = filter(lambda x:x % 2 == 0,arr_number)
print(list(result))








